package com.vhuomai.product.label.controller;

import com.quanyue.auto.util.ServiceResult;
import com.quanyue.auto.web.Scope;
import com.vhuomai.product.label.dto.LabelProductReq;
import com.vhuomai.product.label.service.LabelProductService;
import com.vhuomai.system.constant.UserRole;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author Cui
 */
@Api(tags = "产品-标签关连")
@RestController
@RequestMapping("/api")
@Scope(role = UserRole.MANAGER)
public class LabelProductController {
    @Autowired
    private LabelProductService labelProductService;

    @ApiOperation(value = "产品贴标签（支持批量）")
    @PostMapping(value = "/product/label/relevance", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public ServiceResult<Boolean> addLabelProduct(@RequestBody LabelProductReq labelProductReq) {
        labelProductService.addProductLabel(labelProductReq);
        return ServiceResult.SUCCESS;
    }

    @ApiOperation(value = "取消产品标签（支持批量）")
    @PutMapping(value = "/product/label/relevance", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public ServiceResult<Boolean> deleteLabelProduct(@RequestBody List<Integer> labelProductIds) {
        labelProductService.deleteProductLabel(labelProductIds);
        return ServiceResult.SUCCESS;
    }
}
